package videostoreapp;

import java.io.Serializable;
import java.sql.Timestamp;
import videowarehouseapp.ApplicationException;

public interface Order {


    public class OrderLineInfo implements Serializable {
    	
        public int order_id;        // which order does this belong to
        public int id;              // order-relative order line id
        public int catalogue_id;    // video foreign key
        public int quantity;        // how many copies being ordered

        public OrderLineInfo (int order_id, int id, int catalogue_id, int quantity)
        {
            this.order_id = order_id;
            this.id = id;
            this.catalogue_id = catalogue_id;
            this.quantity = quantity;
        }
    }
    
    public class OrderInfo implements Serializable{
    	
        public int id;	            // unique order record id
        public int customerId;	    // who is ordering them
        public float total;	        // cost of order
        public OrderLineInfo[] videos; // videos being ordered 
        public Timestamp orderDate;  // when order was placed
        public String warehouse;    // warehouse handling order
        public String store;        // store where was placed
        public int status;	        // status of order 
        public static class OrderStatus{
        	public static int PENDING = 1;
        	public static int SUBMITTED = 2;
                public static int ACCEPTED = 3;
        	public static int DELIVERED = 4;
                public static int BACKORDER = 5;
        }
        //public enum OrderStatus { PENDING, SUBMITTED, ACCEPTED, DELIVERED };

        public OrderInfo(int id, int customerId, float total, Timestamp orderDate, String warehouse, String store, int status)
        {
            this.id = id;
            this.customerId = customerId;
            this.total = total;
            this.videos = new OrderLineInfo[1];
            this.orderDate = orderDate;
            this.warehouse = warehouse;
            this.store = store;
            this.status = status;
        }
    }

    /**
     * Create a new order record and its orderline records and return its order id.
     * The customer who is ordering has to be validated. Videos being ordered could
     * also be validated here as well.
     *  
     * @param order
     * @return
     */ 
    public int createOrder(OrderInfo order) throws ApplicationException;

    /**
     *  Modify attributes of an order. 
     * @param order
     */
    public void modifyOrder(OrderInfo order) throws ApplicationException;

    /** 
     * Submit an order for processing. Results in a delivery request going to the 
     * chosen warehouse. 
     * 
     * @param id
     */
    public void submitOrder(int id) throws ApplicationException;

    /**
     * Deletes an order record (and all its dependent records) given its id 
     * @param id
     */
    public void deleteOrder(int id); 

    /**
     * Returns a order record by a id
     * @param id
     * @return
     */
    public OrderInfo getOrderById(int id);

    /**
     * Updates delivery status of an order
     * @param id
     * @param newStatus
     */
    public void updateOrderStatus(int id, int newStatus);

    /**
     *  Calculate cost of order
     * @param order
     * @return
     */
    public float calculateOrderCost(OrderInfo order);

    /**
     * Validate order - check all foreign keys are valid
     * @param order
     */
    public void validateOrder(OrderInfo order) throws ApplicationException;
}
